<?php

/**
 * JingYao-backend
 *
 * @link     https://gitee.com/wang-zhihui-release/jingyao-backend
 * @apiDocument https://gitee.com/wang-zhihui-release/jingyao-backend/wikis/
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Company.
 * @property string check_message
 * @property int check_status
 * @property int register_user_id
 * @property int register_admin_user_id
 * @property string legal_person_id_card_number
 * @property string brief
 */
class Company extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $guarded = [];

    protected $casts = [
        'push_time' => 'date:Y-m-d',
        'set_up_date' => 'date:Y-m-d',
    ];

    public function getCoverUrlAttribute($value)
    {
        if (substr($value, 0, 4) != 'http') {
            return config('app.url') . $value;
        }
        return $value;
    }

    public function getBusinessLicenseAttribute($value)
    {
        if (empty($value)) {
            return $value;
        }
        if (substr($value, 0, 4) != 'http') {
            return config('app.url') . $value;
        }
        return $value;
    }

    public function assessLog()
    {
        return $this->hasMany(CompanyAssessLog::class);
    }
}
